/**
 * 版权所有 (C), 2019-2019, XXX有限公司
 * 项目名：com.company.study.designpatterns.observer
 * 文件名: AbstractSubject
 * 日期: 2019/6/16 13:56
 * 说明:
 */
package com.company.study.designpatterns.observer;

import java.util.Vector;

/**
 * 被观察者抽象类
 *
 * @author Anbang713
 * @create 2019/6/16
 */
public abstract class AbstractSubject implements Subjectable {

    /**
     * 观察者列表
     */
    private Vector<Observerable> observers = new Vector();

    @Override
    public void addObserver(Observerable observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observerable observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObserver(Object object) {
        observers.forEach(observer -> {
            observer.update(object);
        });
    }
}